package com.itheima.demo;

import java.util.Scanner;

public class MovieOperator {
    private Movie[] movies;     //记住一个电影对象的数组

    public MovieOperator(Movie[] movies) {
        this.movies=movies;
    }

    //打印全部电影信息
    public void printAllMovies() {
        System.out.println("-------------------全部电影信息如下------------------");
        for (int i = 0; i < movies.length; i++) {
            Movie m=movies[i];
            System.out.println(m.getId()+"\t"+m.getName()+"\t"+m.getPrice()+"\t"+m.getActor()+"\t");
        }

    }

    public void searchMoviesById() {
        System.out.println("请输入要查询的电影id:");
        Scanner sc =new Scanner(System.in);
        int id=sc.nextInt();
        for (int i = 0; i < movies.length; i++) {
            //遍历拿到当前遍历到的电影对象
            Movie m=movies[i];
            //判断当前电影对象的id是否是我们当前正在找的id
            if(m.getId()==id){
                System.out.println(m.getId() + "\t" + m.getName() + "\t" + m.getPrice() + "\t" + m.getActor() + "\t");
                return;
            }
        }
        System.out.println("没有找到该电影");
    }
}
